package com.wangjiyuan.shiwupai.mine.activitiy;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.wangjiyuan.shiwupai.R;
import com.wangjiyuan.shiwupai.adapter.MyCollectionViewPagerAdapter;
import com.wangjiyuan.shiwupai.base.BaseActivity;
import com.wangjiyuan.shiwupai.mine.fragment.ItemMyCollectionArticleFragment;
import com.wangjiyuan.shiwupai.mine.fragment.ItemMyCollectionFoodFragment;

import java.util.ArrayList;
import java.util.List;

public class MyCollectionActivity extends BaseActivity {

    private Toolbar toolBar_myCollection_back;
    private ViewPager vp_myCollection_item;
    private List<Fragment> fragmentList;
    private MyCollectionViewPagerAdapter myCollectionViewPagerAdapter;
    private TabLayout tab_myCollection_item;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_collection);

        initData();
        initViewPager();
        initTabLayout();
        initToolBar();
    }

    private void initTabLayout() {
        tab_myCollection_item = (TabLayout) findViewById(R.id.tab_myCollection_item);
        tab_myCollection_item.setupWithViewPager(vp_myCollection_item);
    }

    private void initViewPager() {
        vp_myCollection_item = (ViewPager) findViewById(R.id.vp_myCollection_item);
        FragmentManager fragmentManager = getSupportFragmentManager();
        myCollectionViewPagerAdapter = new MyCollectionViewPagerAdapter(fragmentManager, fragmentList);
        vp_myCollection_item.setAdapter(myCollectionViewPagerAdapter);
    }

    private void initData() {
        fragmentList = new ArrayList<>();
        ItemMyCollectionArticleFragment articleFragment = new ItemMyCollectionArticleFragment();
        ItemMyCollectionFoodFragment foodFragment = new ItemMyCollectionFoodFragment();
        fragmentList.add(articleFragment);
        fragmentList.add(foodFragment);
    }

    private void initToolBar() {
        toolBar_myCollection_back = (Toolbar) findViewById(R.id.toolBar_myCollection_back);
        toolBar_myCollection_back.setTitle("我的收藏");
        toolBar_myCollection_back.setNavigationIcon(R.mipmap.icon_back_black);
        toolBar_myCollection_back.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }
}
